Median Rent (single family residential)

rentalCity <- read_csv("City_MedianRentalPrice_Sfr.csv") %>% 
  select(RegionName, State, Metro, CountyName, SizeRank, 
         starts_with("2016"),
         starts_with("2017"),
         starts_with("2018")) %>% 
  filter(State == "CO",
         RegionName %in% c("Denver",
                           "Lakewood",
                           "Englewood",
                           "Edgewater",
                           "Golden",
                           "Wheat Ridge",
                           "Westminster",
                           "West Pleasant View")) %>% 
  gather(date, rent, `2016-01`:`2018-12`)
## Parsed with column specification:
## cols(
##   .default = col_double(),
##   RegionName = col_character(),
##   State = col_character(),
##   Metro = col_character(),
##   CountyName = col_character(),
##   SizeRank = col_integer(),
##   `2010-01` = col_integer()
## )
## See spec(...) for full column specifications.
ggplot(data = rentalCity %>% 
         mutate(label = if_else(date == "2018-12", RegionName, NA_character_)),
       aes(x = date, y = rent, color = RegionName, group = RegionName)) +
  geom_line() +
  scale_x_discrete(expand = expand_scale(mult = c(0, 0.25))) +
  geom_label_repel(aes(label = label),
                  nudge_x = 1,
                  na.rm = TRUE) +
  scale_color_brewer(palette = "Dark2") +
  labs(x = "date", y = "median rent (SFR)") +
  theme(legend.position = "none",
        axis.text.x = element_text(angle = 45, hjust = 1))
## Warning: Removed 37 rows containing missing values (geom_path).

placeRent <- read_csv("City_MedianRentalPrice_Sfr.csv") %>% 
  select(RegionName, State, Metro, CountyName, SizeRank, rent = `2019-01`) %>% 
  filter(State == "CO")
## Parsed with column specification:
## cols(
##   .default = col_double(),
##   RegionName = col_character(),
##   State = col_character(),
##   Metro = col_character(),
##   CountyName = col_character(),
##   SizeRank = col_integer(),
##   `2010-01` = col_integer()
## )
## See spec(...) for full column specifications.
# Load shapefile
coloradoPlaces <- st_read("tl_2018_08_place") %>%
  st_crop(xmin = -105.5, xmax = -103.5, ymin = 39, ymax = 40.5) %>% 
  left_join(placeRent, by = c("NAME" = "RegionName"))
## Reading layer `tl_2018_08_place' from data source `C:\Users\Nat\Documents\R_Projects\denver-rentals\tl_2018_08_place' using driver `ESRI Shapefile'
## Simple feature collection with 458 features and 16 fields
## geometry type:  MULTIPOLYGON
## dimension:      XY
## bbox:           xmin: -109.0181 ymin: 37.0002 xmax: -102.0781 ymax: 40.9967
## epsg (SRID):    4269
## proj4string:    +proj=longlat +datum=NAD83 +no_defs
## although coordinates are longitude/latitude, st_intersection assumes that they are planar
## Warning: attribute variables are assumed to be spatially constant
## throughout all geometries
## Warning: Column `NAME`/`RegionName` joining factor and character vector,
## coercing into character vector
# Color palette
pal <- colorNumeric("YlOrRd", domain = coloradoPlaces$rent)
# pal <- colorQuantile("YlOrRd", domain = coloradoPlaces$ZRI, probs = seq(0, 1, by = 0.1))

labels <- sprintf(
  "<strong>%s</strong><br/>Median rent (SFR): %g",
  coloradoPlaces$NAME, coloradoPlaces$rent
) %>% lapply(htmltools::HTML)

# Create leaflet chloropleth
leaflet(coloradoPlaces) %>%
  addTiles() %>%
  addPolygons(
    fillColor = ~ pal(rent),
    weight = 1,
    opacity = 1,
    color = "black",
    dashArray = "3",
    fillOpacity = 0.7,
    highlight = highlightOptions(
      weight = 2,
      color = "#666",
      dashArray = "",
      fillOpacity = 0.7,
      bringToFront = TRUE),
    label = labels,
    labelOptions = labelOptions(
      style = list("font-weight" = "normal", padding = "3px 8px"),
      textsize = "15px",
      direction = "auto")
  ) %>% 
  addLegend(
    pal = pal, 
    values = ~ rent,
    opacity = 0.7, 
    title = "Median Rent (SFR)",
    position = "bottomright")
## Warning: sf layer has inconsistent datum (+proj=longlat +datum=NAD83 +no_defs).
## Need '+proj=longlat +datum=WGS84'

Zillow Rent Index (single family residential)

rentalCity <- read_csv("City_Zri_SingleFamilyResidenceRental.csv") %>% 
  select(RegionName, State, Metro, CountyName, SizeRank, 
         starts_with("2016"),
         starts_with("2017"),
         starts_with("2018")) %>% 
  filter(State == "CO",
         RegionName %in% c("Denver",
                           "Lakewood",
                           "Englewood",
                           "Edgewater",
                           "Golden",
                           "Wheat Ridge",
                           "Westminster",
                           "West Pleasant View")) %>% 
  gather(date, rent, `2016-01`:`2018-12`)
## Parsed with column specification:
## cols(
##   .default = col_integer(),
##   RegionName = col_character(),
##   State = col_character(),
##   Metro = col_character(),
##   CountyName = col_character()
## )
## See spec(...) for full column specifications.
ggplot(data = rentalCity %>% 
         mutate(label = if_else(date == "2018-12", RegionName, NA_character_)),
       aes(x = date, y = rent, color = RegionName, group = RegionName)) +
  geom_line() +
  scale_x_discrete(expand = expand_scale(mult = c(0, 0.25))) +
  geom_label_repel(aes(label = label),
                  nudge_x = 1,
                  na.rm = TRUE) +
  scale_color_brewer(palette = "Dark2") +
  labs(x = "date", y = "Zillow rent index (SFR)") +
  theme(legend.position = "none",
        axis.text.x = element_text(angle = 45, hjust = 1))

placeRent <- read_csv("City_Zri_SingleFamilyResidenceRental.csv") %>% 
  select(RegionName, State, Metro, CountyName, SizeRank, rent = `2019-01`) %>% 
  filter(State == "CO")
## Parsed with column specification:
## cols(
##   .default = col_integer(),
##   RegionName = col_character(),
##   State = col_character(),
##   Metro = col_character(),
##   CountyName = col_character()
## )
## See spec(...) for full column specifications.
# Load shapefile
coloradoPlaces <- st_read("tl_2018_08_place") %>%
  st_crop(xmin = -105.5, xmax = -103.5, ymin = 39, ymax = 40.5) %>% 
  left_join(placeRent, by = c("NAME" = "RegionName"))
## Reading layer `tl_2018_08_place' from data source `C:\Users\Nat\Documents\R_Projects\denver-rentals\tl_2018_08_place' using driver `ESRI Shapefile'
## Simple feature collection with 458 features and 16 fields
## geometry type:  MULTIPOLYGON
## dimension:      XY
## bbox:           xmin: -109.0181 ymin: 37.0002 xmax: -102.0781 ymax: 40.9967
## epsg (SRID):    4269
## proj4string:    +proj=longlat +datum=NAD83 +no_defs
## although coordinates are longitude/latitude, st_intersection assumes that they are planar
## Warning: attribute variables are assumed to be spatially constant
## throughout all geometries
## Warning: Column `NAME`/`RegionName` joining factor and character vector,
## coercing into character vector
# Color palette
pal <- colorNumeric("YlOrRd", domain = coloradoPlaces$rent)
# pal <- colorQuantile("YlOrRd", domain = coloradoPlaces$ZRI, probs = seq(0, 1, by = 0.1))

labels <- sprintf(
  "<strong>%s</strong><br/>Zillow rent index (SFR): %g",
  coloradoPlaces$NAME, coloradoPlaces$rent
) %>% lapply(htmltools::HTML)

# Create leaflet chloropleth
leaflet(coloradoPlaces) %>%
  addTiles() %>%
  addPolygons(
    fillColor = ~ pal(rent),
    weight = 1,
    opacity = 1,
    color = "black",
    dashArray = "3",
    fillOpacity = 0.7,
    highlight = highlightOptions(
      weight = 2,
      color = "#666",
      dashArray = "",
      fillOpacity = 0.7,
      bringToFront = TRUE),
    label = labels,
    labelOptions = labelOptions(
      style = list("font-weight" = "normal", padding = "3px 8px"),
      textsize = "15px",
      direction = "auto")
  ) %>% 
  addLegend(
    pal = pal, 
    values = ~ rent,
    opacity = 0.7, 
    title = "Zillow Rent Index (SFR)",
    position = "bottomright")
## Warning: sf layer has inconsistent datum (+proj=longlat +datum=NAD83 +no_defs).
## Need '+proj=longlat +datum=WGS84'